package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/api/taobao")
public class TaobaoController  extends BaseController {

    @Autowired
    private RestTemplate restTemplate;

    public static class MaterialsRequest {
        private String keyword;
        private Integer materialType = 1;

        public String getKeyword() {
            return keyword;
        }

        public void setKeyword(String keyword) {
            this.keyword = keyword;
        }

        public Integer getMaterialType() {
            return materialType;
        }

        public void setMaterialType(Integer materialType) {
            this.materialType = materialType;
        }
    }

    public static class ItemRequest {
        private String itemId;

        public String getItemId() {
            return itemId;
        }

        public void setItemId(String itemId) {
            this.itemId = itemId;
        }
    }

    @Anonymous
    @PostMapping("/materials")
    public AjaxResult getMaterials(@RequestBody MaterialsRequest request) {
        String url = "http://47.111.154.179:8030/api/taobao/materials";
        return success(restTemplate.postForEntity(url, request, String.class));
    }

    @Anonymous
    @PostMapping("/materials/item")
    public AjaxResult getMaterialsItem(@RequestBody MaterialsRequest request) {
        String url = "http://47.111.154.179:8030/api/material/sync/itemId";
        ItemRequest itemRequest = new ItemRequest();
        itemRequest.setItemId(request.getKeyword());
        return success(restTemplate.postForEntity(url, itemRequest, String.class));
    }
} 